﻿Imports extranet.BE
Imports extranet.BC

Partial Class Eventos_Evento
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim strIdEvento As String = Request.QueryString("Id")
            Dim objBEEvento As BEEvento = BCEvento.SelecionarEvento(strIdEvento)
            Accordion1.DataSource = objBEEvento.TelasEvento
            Accordion1.DataBind()
        End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim objBEInscrito As New extranet.BE.BEInscrito()
        Dim strIdEvento As String = Request.QueryString("Id")

        objBEInscrito.Nome = Nome.Text
        objBEInscrito.IdEvento = strIdEvento
        objBEInscrito.Aprovado = False
        objBEInscrito.Cep = Cep.Text
        objBEInscrito.Cidade = Cidade.Text
        objBEInscrito.Cpf = CPF.Text
        objBEInscrito.DataNascimento = New Date(Convert.ToInt32(Nascimento.Text.Split("/")(2)), Convert.ToInt32(Nascimento.Text.Split("/")(1)), Convert.ToInt32(Nascimento.Text.Split("/")(0)))
        objBEInscrito.Email = Email.Text
        objBEInscrito.Endereco = Endereco.Text
        objBEInscrito.Estado = UF.Text
        objBEInscrito.Pais = Pais.Text
        objBEInscrito.TelefoneCelular = Celular.Text
        objBEInscrito.TelefoneResidencial = Residencial.Text
        objBEInscrito.Sexo = Sexo.SelectedValue.ToString()

        Try
            If BCInscrito.VerificarCPF(strIdEvento, objBEInscrito.Cpf) Then
                If Nome.Text.Contains(" ") Then
                    lblErroNome.Visible = False
                    extranet.BC.BCInscrito.InscreverNoEvento(strIdEvento, objBEInscrito)
                    Response.Redirect("http://extranet.fit4.com.br/Eventos/Sucesso.aspx")
                Else
                    lblErroNome.Visible = True
                End If
            Else
                System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
                System.Web.HttpContext.Current.Response.Write("alert(""Este CPF já está inscrito neste evento!"")" & vbCrLf)
                System.Web.HttpContext.Current.Response.Write("</SCRIPT>")
            End If

        Catch ex As ApplicationException
            System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
            System.Web.HttpContext.Current.Response.Write("alert(""Erro!"")" & vbCrLf)
            System.Web.HttpContext.Current.Response.Write("</SCRIPT>")
        End Try
    End Sub
End Class
